import {Component, OnInit, Provider} from "@angular/core";
import {IndexHttpService} from "./shared/service/index-http.service";
import {CommodityTypeModel} from "../shared/model/commodity-type.model";
import {NgbPaginationConfig} from "@ng-bootstrap/ng-bootstrap";
/**
 * 主页组件类
 * Created by Administrator on 2016/12/1.
 */

@Component({
    selector: "index",
    templateUrl: "./index.component.html",
    styleUrls: ["./style-source/index.component.scss"],
})
export class IndexComponent implements OnInit {
    //该变量用于存储初始化页面时，需从服务器获得的初始化信息
    allImgSrc: string[] = [];
    commodityTypeInfo: CommodityTypeModel[] = [];
    //该变量用于记录当前选中的商品类型
    currTypeIndex: number = 0;

    constructor(private indexHttpService: IndexHttpService) {
    }

    ngOnInit() {
        this.selectIndexCarouselImg();
        this.selectCommodityTypeInfo();
    }

    //这个方法用于在组件初始化后从服务器获取主页轮播图信息
    private selectIndexCarouselImg() {
        this.indexHttpService.selectIndexCarouselImg()
            .subscribe((imgUrlArr: string[]) => {
                this.allImgSrc = imgUrlArr;
            }, (error) => {
                alert(error);
            })
    }

    //该方法用于获得所有的商品类型
    private selectCommodityTypeInfo() {
        this.indexHttpService.selectCommodityTypeInfo()
            .subscribe((data: CommodityTypeModel[]) => {
                this.commodityTypeInfo = data;
                this.selectCommodityInfo(data[0].id);
            });
    }

    //这个方法用于从服务器获得主页商品的信息
    private selectCommodityInfo(id: number) {
    }
}